<template>
  <div class="adminmoban">
    <admin_top></admin_top>
    <div style="padding: 0 20px;">
      <el-table :data="tableData" style="text-align: center;" align="center" border :loading="loading">
        <el-table-column label="模板名称">
          <template slot-scope="scope">
            <span>{{ scope.row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="scope">
            <span v-if="scope.row.status == 0"> 待审核</span>
            <span v-if="scope.row.status == 1"> 通过</span>
            <span v-if="scope.row.status == 2"> 拒绝</span>
          </template>
        </el-table-column>
        <el-table-column label="审核失败原因">
          <template slot-scope="scope">
            <span>{{ scope.row.reason }}</span>
          </template>
        </el-table-column>

        <el-table-column label="类型">
          <template slot-scope="scope">
            <span v-if="scope.row.type == 1">下单提醒</span>
            <span v-if="scope.row.type == 2">订单信息完善</span>
            <span v-if="scope.row.type == 3">开卡结果通知</span>
            <span v-if="scope.row.type == 4">发货通知</span>
            <span v-if="scope.row.type == 5">催促激活</span>
            <span v-if="scope.row.type == 6">其他</span>
            <span v-if="scope.row.type == 7">营销类短信</span>
          </template>
        </el-table-column>

        <el-table-column label="内容">
          <template slot-scope="scope">
            <span>{{ scope.row.content }}</span>
          </template>
        </el-table-column>

        <el-table-column label="短信渠道">
          <template slot-scope="scope">
            <span>{{ scope.row.type }}</span>
          </template>
        </el-table-column>

        <el-table-column label="创建时间">
          <template slot-scope="scope">
            <span>{{ scope.row.created_at }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="shenhe(1,scope.row.id)">审核通过</el-button>
            <el-button type="text" @click="shenhe(2,scope.row.id)">审核拒绝</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>


  </div>
</template>

<script>
  import admin_top from './top.vue';
  import axios from 'axios'
  export default {
    components: {
      admin_top
    },
    name: 'adminmoban',
    data() {
      return {
        all: {
          pagesize: 20,
          page: 1,
        },
        tableData: "",
        total: "",
        loading: true
      }
    },
    watch: {

    },
    computed: {

    },
    created() {
      this.getlist()
    },
    methods: {
      shenhe: function(status, id) {
        if (status == 2) {
          this.$prompt('请输入拒绝的理由', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
          }).then(({
            value
          }) => {
            axios.post('/api/plan-market/message/formwork/review', {
                status: status,
                id: id,
                reason: value
              })
              .then(response => {
                if (response.data.msg.code == 0) {
                  this.$message.success('已拒绝');
                  this.getlist()
                } else {
                  this.$message.error(response.data.msg.info);
                }
              })
          })
        } else {
          axios.post('/api/plan-market/message/formwork/review', {
              status: status,
              id: id
            })
            .then(response => {
              if (response.data.msg.code == 0) {
                this.$message.success('已通过');
                this.getlist()
              } else {
                this.$message.error(response.data.msg.info);
              }
            })
        }


      },
      //翻页
      fanye: function(page) {
        this.loading = true
        this.all.page = page
        this.getlist()
      },
      //获取全部
      getlist: function() {
        var that = this
        axios.get('/api/plan-market/message/pending/approval')
          .then(response => {
            if (response.data.msg.code == 0) {
              this.tableData = response.data.data

              this.loading = false
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },

    },

  }
</script>

<style scoped>
  .adminmoban {
    background: #EAEAEA;
    min-height: 100vh;
    box-sizing: border-box;
  }
</style>
